use "$path\datasets\ivdata", clear


merge m:1 gkz legislative_period using "TableA21/closeelcbavaria"


replace tot_share_women_elected=tot_share_women_elected*100

preserve
bysort gkz legislative_period: keep if _n==1
ivreg2 tot_share_women_elected total_belec_women , r cluster(gkz )
est store m1
sum tot_share_women_elected if e(sample)
estadd scalar  mean_depvar =r(mean)
estadd scalar sd_depvar =r(sd)
restore

ivreg2 ch_total_child_places_pc total_belec_women , r cluster(gkz )
est store m2
sum ch_total_child_places_pc if e(sample)
estadd scalar  mean_depvar =r(mean)
estadd scalar sd_depvar =r(sd)

ivreg2 ch_total_child_places_pc (tot_share_women_elected =total_belec_women) , r cluster(gkz )
est store m3
sum ch_total_child_places_pc if e(sample)
estadd scalar  mean_depvar =r(mean)
estadd scalar sd_depvar =r(sd)





esttab  m1 m2 m3 using TableA21/tableA21.txt, style(tab) replace order( ) mlabel(,none) ///
cells(b(label(coef.) star fmt(%8.3f) ) se(label((z)) par fmt(%6.3f))) ///
collabels(none) ///
keep ( total_belec_women   tot_share_women_elected   ) ///
  stats( N   N_clust mean_depvar sd_depvar , layout( @  @  `""@ (@)""' )  fmt(  %9.0g %9.0g  %9.2f %9.2f  ) ///
 labels(  "N"  "Municipalities" "Mean (SD)"  )) ///
starlevels(* 0.10 ** 0.05 *** 0.01) ///
  varlabels( total_belec_women "No. of women elected in close races" tot_share_women_elected "Share of women"   )  


